package com.zuo.mall.controller;

import com.zuo.mall.common.api.CommonPage;
import com.zuo.mall.common.api.CommonResult;
import com.zuo.mall.dto.OmsOrderReturnApplyResult;
import com.zuo.mall.dto.OmsReturnApplyQueryParam;
import com.zuo.mall.dto.OmsUpdateStatusParam;
import com.zuo.mall.entity.OmsOrderReturnApply;
import com.zuo.mall.service.OmsOrderReturnApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("退货申请处理")
@RestController
@RequestMapping("returnApply")
public class OmsOrderReturnApplyController {

    @Autowired
    private OmsOrderReturnApplyService orderReturnApplyService;
    @GetMapping("list")
    public CommonResult<CommonPage<OmsOrderReturnApply>> list(
            OmsReturnApplyQueryParam omsReturnApplyQueryParam,
            @RequestParam ("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize
    ) {
        CommonPage<OmsOrderReturnApply> omsOrderReturnApplyCommonPage = orderReturnApplyService.list(omsReturnApplyQueryParam, pageNum, pageSize);
        return CommonResult.success(omsOrderReturnApplyCommonPage);
    }

    @ApiOperation("获取退款申请详情")
    @GetMapping("{id}")
    public CommonResult<OmsOrderReturnApplyResult> getItem(@PathVariable("id") Long id) {
        OmsOrderReturnApplyResult result = orderReturnApplyService.getOrderReturnApplyResultById(id);
        return CommonResult.success(result);
    }

    @PostMapping("update/status/{id}")
    public CommonResult updateStatus(@PathVariable("id") Long id, @RequestBody OmsUpdateStatusParam omsUpdateStatusParam) {
        int count = orderReturnApplyService.updateStatus(id, omsUpdateStatusParam);
        if (count>0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @PostMapping("delete")
    public CommonResult deleteOrder(@RequestParam List<Long> ids) {
        boolean b = orderReturnApplyService.removeByIds(ids);
        if (b) return CommonResult.success(1);
        return CommonResult.failed();
    }
}
